package com.bh.web.controller.order;

import com.bh.common.annotation.Log;
import com.bh.common.core.controller.BaseController;
import com.bh.common.core.domain.AjaxResult;
import com.bh.common.core.page.TableDataInfo;
import com.bh.common.enums.BusinessType;
import com.bh.common.utils.poi.ExcelUtil;
import com.bh.order.domain.JcInOrOutRecord;
import com.bh.order.service.IJcInOrOutRecordService;
import com.bh.order.vo.JcInOrOutRecordVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出入库记录Controller
 * 
 * @author slx
 * @date 2023-12-17
 */
@RestController
@RequestMapping("/order/inoroutrecord")
public class JcInOrOutRecordController extends BaseController
{
    @Autowired
    private IJcInOrOutRecordService jcInOrOutRecordService;

    /**
     * 查询出入库记录列表
     */
    @ApiOperation("查询出入库记录列表")
    @PreAuthorize("@ss.hasPermi('order:inoroutrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(JcInOrOutRecordVo jcInOrOutRecord)
    {
        startPage();
        if (jcInOrOutRecord.getJcOrganizationId() == null) {
            jcInOrOutRecord.setJcOrganizationId(getOrgId());
        }
        List<JcInOrOutRecordVo> list = jcInOrOutRecordService.selectJcInOrOutRecordList(jcInOrOutRecord);
        return getDataTable(list);
    }

    /**
     * 导出出入库记录列表
     */
    @PreAuthorize("@ss.hasPermi('order:inoroutrecord:export')")
    @Log(title = "出入库记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JcInOrOutRecordVo jcInOrOutRecord)
    {
        if (jcInOrOutRecord.getJcOrganizationId() == null) {
            jcInOrOutRecord.setJcOrganizationId(getOrgId());
        }
        List<JcInOrOutRecordVo> list = jcInOrOutRecordService.selectJcInOrOutRecordList(jcInOrOutRecord);
        ExcelUtil<JcInOrOutRecordVo> util = new ExcelUtil<>(JcInOrOutRecordVo.class);
        util.exportExcel(response, list, "出入库记录数据");
    }

    /**
     * 获取出入库记录详细信息
     */
    @ApiOperation("获取出入库记录详细信息")
    @PreAuthorize("@ss.hasPermi('order:inoroutrecord:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(jcInOrOutRecordService.selectJcInOrOutRecordById(id));
    }

    /**
     * 新增出入库记录
     */
    @ApiOperation("新增出入库记录")
    @PreAuthorize("@ss.hasPermi('order:inoroutrecord:add')")
    @Log(title = "出入库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JcInOrOutRecord jcInOrOutRecord)
    {
        return toAjax(jcInOrOutRecordService.insertJcInOrOutRecord(jcInOrOutRecord));
    }

    /**
     * 修改出入库记录
     */
    @ApiOperation("修改出入库记录")
    @PreAuthorize("@ss.hasPermi('order:inoroutrecord:edit')")
    @Log(title = "出入库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JcInOrOutRecord jcInOrOutRecord)
    {
        return toAjax(jcInOrOutRecordService.updateJcInOrOutRecord(jcInOrOutRecord));
    }

    /**
     * 删除出入库记录
     */
    @ApiOperation("删除出入库记录")
    @PreAuthorize("@ss.hasPermi('order:inoroutrecord:remove')")
    @Log(title = "出入库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(jcInOrOutRecordService.deleteJcInOrOutRecordByIds(ids));
    }
}
